package com.hnevc.yourhealthmanager.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnevc.yourhealthmanager.dto.DietRecordDTO;
import com.hnevc.yourhealthmanager.entity.DietRecord;
import com.hnevc.yourhealthmanager.entity.HealthPlane;
import com.hnevc.yourhealthmanager.dao.DietRecordMapper;
import com.hnevc.yourhealthmanager.entity.SportRecord;
import com.hnevc.yourhealthmanager.service.DietRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DietRecordServiceImpl extends ServiceImpl<DietRecordMapper, DietRecord> implements DietRecordService {
    @Autowired
    DietRecordMapper dietRecordMapper;

    public  List<DietRecordDTO> selectDietRecordByUserId(Integer userId) {
        return dietRecordMapper.selectDietRecordByUserId(userId);
    }

    @Override
    public List<DietRecordDTO> getDietRecordListByHealthPlane(HealthPlane healthPlane) {
        return dietRecordMapper.getDietRecordListByHealthPlane(healthPlane);
    }

    @Override
    public List<DietRecordDTO> getDietRecordListByPlaneMonth(HealthPlane healthPlane, Integer month, Integer year) {
        return dietRecordMapper.getDietRecordListByPlaneMonth(healthPlane, month, year);
    }
    @Override
    public DietRecord updatePic(Integer id, String filePath) {
        DietRecord dietRecord= dietRecordMapper.selectById(id);
        dietRecord.setDietImage(filePath);
        if(dietRecordMapper.updateById(dietRecord)>0){
            return dietRecord;
        }else{
            return null;
        }
    }
}
